#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/11/30 19:26
# @Author  : FuKai ZHANG
# @File    : index_page.py
# @Description :
from utils.PageConfigFiles_tools.get_PageElementconFile import ParseConFile
from utils.Mouse_Actions.mouse_action import MouseActions
from Pages.Basepage import BasePage
from utils.Logging_tools.log_control import INFO


class IndexPage(BasePage):
    index_iframe = ParseConFile().get_locators("IndexPage", "index_iframe")
    user_center = ParseConFile().get_locators("IndexPage", "user_center")
    personal_information = ParseConFile().get_locators("IndexPage", "personal_information")
    personal_iframe = ParseConFile().get_locators("IndexPage", "personal_iframe")
    chang_head_portrait = ParseConFile().get_locators("IndexPage", "chang_head_portrait")
    logout = ParseConFile().get_locators("IndexPage", "logout")
    upload_file_iframe = ParseConFile().get_locators("IndexPage", "upload_file_iframe")
    upload_file_save = ParseConFile().get_locators("IndexPage", "upload_file_save")

    def change_head_portrait(self):
        """更换头像的流程（在自动登录的前提下）"""
        INFO.logger.info("<=开始更换头像流程=>")
        # 先切换到iframe
        self.switch_to_frame(*IndexPage.index_iframe, model="首页iframe")
        # 然后鼠标悬停在用户中心
        MouseActions(self.driver).mouse_hover(self.wait_element_to_be_located(*IndexPage.user_center, model="用户中心"))
        # 然后点击个人档案
        self.click(*IndexPage.personal_information, model="档案")
        #
        self.switch_to_frame(*IndexPage.personal_iframe, model="个人档案iframe")
        # 然后点击更换头像
        self.click(*IndexPage.chang_head_portrait, model="更换头像")
        # 上传头像
        self.upload_file("123.jpg")
        # 切换到上传后的裁剪iframe,先切回父级iframe，再切到首页iframe,再切当前iframe
        self.switch_to_default_frame()
        self.switch_to_frame(*IndexPage.index_iframe, model="首页iframe")
        self.switch_to_frame(*IndexPage.upload_file_iframe, model="上传后的裁剪iframe")
        # 点击保存
        self.click(*IndexPage.upload_file_save, model="保存")

    def log_out(self):
        """退出登录"""
        INFO.logger.info("<=开始退出登录流程=>")
        # 先切换到iframe
        self.switch_to_frame(*IndexPage.index_iframe, model="首页iframe")
        # 然后鼠标悬停在用户中心
        MouseActions(self.driver).mouse_hover(self.wait_element_to_be_located(*IndexPage.user_center, model="用户中心"))
        # 然后点击退出登录
        self.click(*IndexPage.logout, model="退出登录")
